<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\helper;

use yii\helpers\Json;

/**
 * XML
 * @author cleverstone
 * @since ym2.0
 */
class Xml
{
    /**
     * XML转数组
     * @param string $xmlStr XML字符串
     * @return array
     */
    public static function toArray($xmlStr)
    {
        $object = simplexml_load_string($xmlStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        $json = Json::encode($object);
        $array = Json::decode($json);

        return $array;
    }
}